'use strict';
exports.main = async (event, context) => {
	// 获取 accessToken
	const apiKey = 'Fp5YjG55rxG3vYKx803eHAYo', secretKey = 'hiN9I0QnrN0biRpQiU8rEYmNWgjfxCEB'
	const res = await uniCloud.httpclient.request(
		`https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=${apiKey}&client_secret=${secretKey}`,
		{
			dataType: 'json'
		}
	)
	const accessToken = res.data.access_token
	// 图像识别
	const classifyRes = await uniCloud.httpclient.request(
		'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general',
		{
			header: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			data: {
				image: event.imageb64,
				access_token: accessToken
			},
			method: 'POST',
			dataType: 'json'
		}
	)
	//返回数据给客户端
	return classifyRes.data
};
